package com.maxmlr.music.system.service.transfer;

import com.maxmlr.music.admin.entity.User;
import com.maxmlr.music.common.util.DateUtil;
import com.maxmlr.music.system.entity.Task;
import com.maxmlr.music.system.param.TaskParam;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;

import java.util.Date;

/**
 * @ClassName TaskTransfer
 * @Description TODO
 * @Author maxiao
 * @Date 2020/6/7 下午10:24
 * @Version V1.0
 */
@Component
public class TaskTransfer {


    public Task po2Task(TaskParam param, User adminUser) {
        Date date = DateUtil.getDate();
        Task task = new Task();
        task.setId(param.getId());
        task.setJobName(param.getJobName());
        task.setMethodName(param.getMethodName());
        task.setCronExpression(param.getCronExpression());
        task.setBeanClass(param.getBeanClass());
        task.setSpringBean(ClassUtils.getShortName(param.getBeanClass()));
        task.setJobGroup(param.getJobGroup());
        task.setDescription(param.getDescription());
        task.setJobStatus(param.getJobStatus());
        task.setCreateUserId(adminUser.getId());
        task.setUpdateUserId(adminUser.getId());
        task.setCreateDate(date);
        task.setUpdateDate(date);
        return task;
    }

    public void fullTask(Task task, TaskParam param, User adminUser) {
        Date date = DateUtil.getDate();
        task.setId(param.getId());
        task.setJobName(param.getJobName());
        task.setMethodName(param.getMethodName());
        task.setCronExpression(param.getCronExpression());
        task.setBeanClass(param.getBeanClass());
        task.setSpringBean(ClassUtils.getShortName(param.getBeanClass()));
        task.setJobGroup(param.getJobGroup());
        task.setDescription(param.getDescription());
        task.setUpdateUserId(adminUser.getId());
        task.setUpdateDate(date);
    }
}
